﻿#ifndef BUTTONDELEGATE_H_
#define BUTTONDELEGATE_H_

#include <QStyledItemDelegate>
#include <QCheckBox>
#include <QStyleOption>
#include <QApplication>
#include <QMouseEvent>
#include <QPainter>
#include <QAbstractItemView>
#include <QEvent>





class ButtonDelegate : public QStyledItemDelegate
{
	Q_OBJECT
private:
	std::vector<std::unique_ptr<QAbstractButton>> m_buttons;
	//按钮间隔：
	int m_spacing{ 6 };
	QPoint m_mousePos;

signals:
	void buttonCilcked(int id,const QModelIndex& index);

public:
	ButtonDelegate(QObject* parent = nullptr);

	QAbstractButton* addButton(QAbstractButton* button);
	QAbstractButton* button(int id);
	int buttontotalwidth(size_t total = -1)const;


protected:
	void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
	bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
};


#endif // !BUTTONDELEGATE_H_
